/* Copyright (C) 2005-2013, Unigine Corp. All rights reserved.
 *
 * File:    vertex_base.h
 * Desc:    Base vertex shader
 * Version: 1.04
 * Author:  Alexander Zapryagaev <frustum@unigine.com>
 *
 * This file is part of the Unigine engine (http://unigine.com/).
 *
 * Your use and or redistribution of this software in source and / or
 * binary form, with or without modification, is subject to: (i) your
 * ongoing acceptance of and compliance with the terms and conditions of
 * the Unigine License Agreement; and (ii) your inclusion of this notice
 * in any version of this software that you use or redistribute.
 * A copy of the Unigine License Agreement is available by contacting
 * Unigine Corp. at http://unigine.com/
 */

#ifndef __VERTEX_BASE_H__
#define __VERTEX_BASE_H__

/******************************************************************************\
*
* OpenGL/OpenGLES
*
\******************************************************************************/

#ifdef OPENGL || OPENGLES

/*
 */
#include <core/shaders/simple/common/common_base.h>

/* compatibility
 */
#if SHADING_LANGUAGE >= 150
	#define attribute in
	#define varying out
#endif

/* tangent basis normalization
 */
half3 getTangentBasis(half3 basis) {
	#ifdef USE_NORMALIZATION
		return normalize(basis);
	#else
		return basis;
	#endif
}

/* vertex transformation
 */
float4 getPosition(float4 vertex) {
	return mul4(s_projection,vertex);
}

/* perspective projection
 */
float4 getProjection(float4 position) {
	return (position + position.w) * 0.5f;
}

/* animation offset vector
 */
fixed2 getAnimationOffset(float angle) {
	float angle_0 = angle * 0.3f;
	float angle_1 = angle * 0.9f;
	fixed sin_0 = sin(angle_0);
	fixed cos_0 = cos(angle_0);
	fixed sin_1 = sin(angle_1);
	fixed cos_1 = cos(angle_1);
	return float2(sin_1 * cos_0,cos_1 * sin_0);
}

/*
 */
#ifdef AMBIENT || PROB
	#include <core/shaders/simple/common/vertex_base_shading.h>
#endif

/******************************************************************************\
*
* Direct3D11/Direct3D119
*
\******************************************************************************/

#elif DIRECT3D11 || DIRECT3D119

/*
 */
#include <core/shaders/simple/common/common_base.h>

/* texture samplers
 */
SamplerState s_sampler_0 : register(s0);
SamplerState s_sampler_1 : register(s1);
SamplerState s_sampler_2 : register(s2);
SamplerState s_sampler_3 : register(s3);
SamplerState s_sampler_4 : register(s4);
SamplerState s_sampler_5 : register(s5);
SamplerState s_sampler_6 : register(s6);
SamplerState s_sampler_7 : register(s7);

/* tangent basis normalization
 */
float3 getTangentBasis(float3 basis) {
	#ifdef USE_NORMALIZATION
		return normalize(basis);
	#else
		return basis;
	#endif
}

/* vertex transformation
 */
float4 getPosition(float4 vertex) {
	return mul4(s_projection,vertex);
}

/* perspective projection
 */
float4 getProjection(float4 position) {
	return (position * float4(1.0f,-1.0f,1.0f,1.0f) + position.w) * 0.5f;
}

/* animation offset vector
 */
float2 getAnimationOffset(float angle) {
	float sin_0,cos_0;
	float sin_1,cos_1;
	sincos(angle * 0.3f,sin_0,cos_0);
	sincos(angle * 0.9f,sin_1,cos_1);
	return float2(sin_1 * cos_0,cos_1 * sin_0);
}

/*
 */
#ifdef AMBIENT || PROB
	#include <core/shaders/simple/common/vertex_base_shading.h>
#endif

#endif

#endif /* __VERTEX_BASE_H__ */
